#include<iostream>
#include<string>
#include<vector>
using std::endl;
using std::cout;
using std::string;
using std::vector;

class Solution {
public:
    int ladderLength(string beginWord, string endWord, vector<string>& wordList);
private:
    int CompareWord(const string &s1,const string &s2);
    bool isInArr(string&end,vector<string>& wordList,int length);
};
int Solution::CompareWord(const string &s1,const string &s2){
    auto it = s1.begin();  //记录hit
    auto it2 = s2.begin(); //记录hot
    int size = 0;
    while(it != s1.end() && it2 != s2.end()){
        //还有个情况没有考虑
        if(*it == *it2){
            ++size;
        }
        //cout<<"it ++"<<endl;
        ++it;
        ++it2;
    }
    return size;
}

bool Solution::isInArr(string&end,vector<string>& wordList,int length){
    for(int i = 0;i <length;i++){
        if(wordList[i]==end){
            return true;
        }
    }
    return false;
}

int Solution::ladderLength(string beginWord, string endWord,vector<string>& wordList){
     int idx=0;
     if(!isInArr(endWord,wordList,wordList.size())){
        cout<<"不存在"<<endl;
        return 0;
     }
     for(int i = 0;i<wordList.size();i++){
        //cout<<beginWord.c_str()<<endl;
        //判断是否和字符串相等，相等就不比较
        if(beginWord.compare(wordList[i]) != 0){
            int size = CompareWord(beginWord,wordList[i]);
            //cout<<size<<endl;
            if(size >= beginWord.size()-1 && beginWord.compare(endWord)!=0){
                cout<<"idx++"<<endl;
                ++idx;
                cout<<idx<<endl;
                beginWord = wordList[i]; 
                //i++;错误 因为这里i++会跳过下一个，我在这里犯错了
                //cout<<begin.c_str()<<endl;
            }
        }
     }
    //cout<<"idx: "<<idx<<endl;
    return idx;
}